/*
 * Copyright (C) 2022-2024, Xiaohua Semiconductor Co., Ltd.
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2022-04-28     CDT          first version
 */

#include <rtthread.h>
#include <rtdevice.h>
#include <board.h>
#include "cpuHc32f460.h"
#include "hc32f460_pwc.h"
#include "hc32f460_utility.h"
#include "hc32f460_rmu.h"

#include "Flash.h"
#include <rtthread.h>
#include <dfs_fs.h>
#include "power.h"

port_init_t TPower_Config[] =
{
	//PORT		   PIN    FUNC      Mode         LTE     INTE   INVE    PUU     DRV         NOD          BFE    Level
//        {.enPort = PortB, Pin00, Func_Gpio, Pin_Mode_Ana, Disable, Disable, Disable, Disable, Pin_Drv_M, Pin_OType_Od, Disable, GPIO_DEFAULT},  // 4.PB0   	5.2V掉电检测   
//        {.enPort = PortB, Pin01, Func_Gpio, Pin_Mode_Ana, Disable, Disable, Disable, Disable, Pin_Drv_M, Pin_OType_Od, Disable, GPIO_DEFAULT},  // 3. PC5 时钟电池检测  
        {.enPort = PortC, Pin14, Func_Gpio, Pin_Mode_Out, Disable, Disable, Disable, Disable, Pin_Drv_M, Pin_OType_Cmos, Disable, HIGH}, // 14.PC4 5V电源
        {.enPort = PortB, Pin02, Func_Gpio, Pin_Mode_Out, Disable, Disable, Disable, Disable, Pin_Drv_M, Pin_OType_Cmos, Disable, LOW},// 29.PE10 3.3V电源
//        {.enPort = PortA, Pin15, Func_Gpio, Pin_Mode_Out, Disable, Disable, Disable, Disable, Pin_Drv_M, Pin_OType_Cmos, Disable, LOW},// 29.PA15 8306电源
//        {.enPort = PortC, Pin10, Func_Gpio, Pin_Mode_Out, Disable, Disable, Disable, Disable, Pin_Drv_M, Pin_OType_Cmos, Disable, HIGH},// 16.PC10 8306复位
};

static void Thread_Task()
{
    InitGPIO(&TPower_Config[0],sizeof(TPower_Config)/sizeof(port_init_t));
    
    rt_thread_mdelay(1000);
    
    qbt_startup();
}

int main(void)
{
    /* set LED_GREEN_PIN pin mode to output */
    //开中断
    ENABLE_CPU_INT;
    
    RMU_ClrResetFlag();//清复位标注
//    anv_leaks_init(stdout);//内存管理初始化

    Thread_Task();
   
//    while (1)
//    {
//        rt_thread_mdelay(1000);
//    }
}

